import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;


public class FrameNewGame extends JFrame {
	
	private static final long serialVersionUID = 7521040330692263467L;
	private JTextField textField_winstconditie;
	private JTextField textField_interval;
	private JFrame newGameFrame = this;
	
	// TODO: tijd tussen 2 zetten en hoeveel op een  rij moeten ook nog ingegeven kunnen worden

	/**
	 * Create the frame
	 */
	public FrameNewGame(final MainWindow mainWindow) {
		super();
		setTitle("Nieuw spelbord");
		final GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.rowHeights = new int[] {0,7,7,7,7,7};
		gridBagLayout.columnWidths = new int[] {0,7,7};
		getContentPane().setLayout(gridBagLayout);
		setBounds(100, 100, 355, 172);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		final JLabel rowsLabel = new JLabel();
		rowsLabel.setText("Rijen:");
		final GridBagConstraints gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.anchor = GridBagConstraints.WEST;
		gridBagConstraints.gridy = 0;
		gridBagConstraints.gridx = 0;
		getContentPane().add(rowsLabel, gridBagConstraints);

		final Component component = Box.createHorizontalStrut(20);
		final GridBagConstraints gridBagConstraints_1 = new GridBagConstraints();
		gridBagConstraints_1.gridy = 0;
		gridBagConstraints_1.gridx = 1;
		getContentPane().add(component, gridBagConstraints_1);

		final JTextField textField_rows = new JTextField();
		textField_rows.setColumns(5);
		final GridBagConstraints gridBagConstraints_2 = new GridBagConstraints();
		gridBagConstraints_2.anchor = GridBagConstraints.EAST;
		gridBagConstraints_2.gridy = 0;
		gridBagConstraints_2.gridx = 2;
		getContentPane().add(textField_rows, gridBagConstraints_2);

		final JLabel colsLabel = new JLabel();
		colsLabel.setText("Kolommen:");
		final GridBagConstraints gridBagConstraints_3 = new GridBagConstraints();
		gridBagConstraints_3.anchor = GridBagConstraints.WEST;
		gridBagConstraints_3.gridy = 1;
		gridBagConstraints_3.gridx = 0;
		getContentPane().add(colsLabel, gridBagConstraints_3);

		final JTextField textField_cols = new JTextField();
		textField_cols.setColumns(5);
		final GridBagConstraints gridBagConstraints_4 = new GridBagConstraints();
		gridBagConstraints_4.anchor = GridBagConstraints.EAST;
		gridBagConstraints_4.gridy = 1;
		gridBagConstraints_4.gridx = 2;
		getContentPane().add(textField_cols, gridBagConstraints_4);

		final JLabel intervalTussen2Label = new JLabel();
		intervalTussen2Label.setText("Interval tussen 2 zetten:");
		final GridBagConstraints gridBagConstraints_7 = new GridBagConstraints();
		gridBagConstraints_7.anchor = GridBagConstraints.WEST;
		gridBagConstraints_7.gridy = 2;
		gridBagConstraints_7.gridx = 0;
		getContentPane().add(intervalTussen2Label, gridBagConstraints_7);

		textField_interval = new JTextField();
		textField_interval.setColumns(5);
		final GridBagConstraints gridBagConstraints_8 = new GridBagConstraints();
		gridBagConstraints_8.anchor = GridBagConstraints.EAST;
		gridBagConstraints_8.gridy = 2;
		gridBagConstraints_8.gridx = 2;
		getContentPane().add(textField_interval, gridBagConstraints_8);

		final JLabel winstconditieLabel = new JLabel();
		winstconditieLabel.setText("Winstconditie:");
		final GridBagConstraints gridBagConstraints_9 = new GridBagConstraints();
		gridBagConstraints_9.anchor = GridBagConstraints.WEST;
		gridBagConstraints_9.gridy = 3;
		gridBagConstraints_9.gridx = 0;
		getContentPane().add(winstconditieLabel, gridBagConstraints_9);

		textField_winstconditie = new JTextField();
		textField_winstconditie.setColumns(5);
		final GridBagConstraints gridBagConstraints_10 = new GridBagConstraints();
		gridBagConstraints_10.anchor = GridBagConstraints.EAST;
		gridBagConstraints_10.gridy = 3;
		gridBagConstraints_10.gridx = 2;
		getContentPane().add(textField_winstconditie, gridBagConstraints_10);

		final Component component_1 = Box.createVerticalStrut(5);
		final GridBagConstraints gridBagConstraints_5 = new GridBagConstraints();
		gridBagConstraints_5.gridy = 4;
		gridBagConstraints_5.gridx = 2;
		getContentPane().add(component_1, gridBagConstraints_5);

		final JPanel panel = new JPanel();
		final GridBagConstraints gridBagConstraints_6 = new GridBagConstraints();
		gridBagConstraints_6.gridy = 5;
		gridBagConstraints_6.gridx = 2;
		getContentPane().add(panel, gridBagConstraints_6);

		final JButton okButton = new JButton();
		okButton.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				newGameFrame.dispose();
				mainWindow.startNewSpel(Integer.parseInt(textField_rows.getText()), Integer.parseInt(textField_cols.getText()), Integer.parseInt(textField_interval.getText()), Integer.parseInt(textField_winstconditie.getText()));				
			}
		});
		okButton.setText("OK");
		panel.add(okButton);

		final JButton cancelButton = new JButton();
		cancelButton.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				newGameFrame.dispose();
			}
		});
		cancelButton.setText("Cancel");
		panel.add(cancelButton);
		getContentPane().add(component_1);
		getContentPane().add(component);
		//
	}

}
